﻿using FFLTask.SRV.ProdService.ViewModelMap.Helper;
using TaskContentModel = FFLTask.SRV.ViewModel.Task.Content;
using TaskModel = FFLTask.SRV.ViewModel.Task;
using Entity = FFLTask.BLL.Entity;
using AutoMapper;
using FFLTask.GLB.Global.Enum;

//TODO: will rename back .TaskMap after removing all FilledBy()
namespace FFLTask.SRV.ViewModelMap.TaskMapAuto
{
    internal class EditModelMap
    {
        internal static void init()
        {
            Mapper.CreateMap<Entity.Task, TaskModel.EditModel>()
                .IgnoreAllNonExisting()
                ;
            Mapper.CreateMap<TaskModel.EditModel, Entity.Task>()
                .ForMember(t => t.Publisher, opt => opt.Ignore())
                .ForMember(t => t.Owner, opt => opt.Ignore())
                .ForMember(t => t.Accepter, opt => opt.Ignore())
                .ForMember(t => t.CurrentStatus, opt => opt.Ignore())
                .IgnoreAllNonExisting()
                ;

            Mapper.CreateMap<Entity.Task, TaskContentModel._PublishModel>()
                .ForMember(t => t.SelectedPriority,
                    opt => opt.MapFrom(e => e.Priority))
                .ForMember(t => t.SelectedDifficulty,
                    opt => opt.MapFrom(e => e.Difficulty))
                .ForMember(p => p.SelectedAccepterId,
                    opt => opt.MapFrom(t => t.Accepter.Id))
                .ForMember(t => t.ExpectedComplete,
                    opt => opt.MapFrom(e => e.ExpectCompleteTime.Split()))
                .IgnoreAllNonExisting()
                ;
            Mapper.CreateMap<TaskContentModel._PublishModel, Entity.Task>()
                .ForMember(t => t.Priority,
                    opt => opt.MapFrom(p => p.SelectedPriority))
                .ForMember(t => t.Difficulty,
                    opt => opt.MapFrom(e => e.SelectedDifficulty))
                .ForMember(p => p.ExpectCompleteTime,
                    opt => opt.MapFrom(p => p.ExpectedComplete.Combine()))
                .ForMember(t => t.Parent, opt => opt.Ignore())
                .ForMember(t => t.Attachments, opt => opt.Ignore())
                .IgnoreAllNonExisting()
                ;

            Mapper.CreateMap<Entity.Task, TaskContentModel._AssignOwnModel>()
                .ForMember(p => p.SelectedOwnerId,
                    opt => opt.MapFrom(t => t.Owner.Id))
                .IgnoreAllNonExisting()
                ;

            Mapper.CreateMap<Entity.Task, TaskContentModel._ProgressModel>()
                .IgnoreAllNonExisting()
                ;

            Mapper.CreateMap<Entity.Task, TaskContentModel._AcceptModel>()
                .IgnoreAllNonExisting()
                ;

            Mapper.CreateMap<TaskModel._AttachmentModel, Entity.Attachment>()
                .ForMember(a => a.Uploader, opt => opt.Ignore())
                .IgnoreAllNonExisting()
                ;
            Mapper.CreateMap<Entity.Attachment, TaskModel._AttachmentModel>()
                .IgnoreAllNonExisting()
                ;
        }
    }
}
